package com.next.muscu.visual;

import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import com.next.muscu.data.ExoType;
import com.next.muscu.data.User;

public class UserJlistCellRender extends DefaultListCellRenderer implements
		ListCellRenderer {

	@Override
	public Component getListCellRendererComponent(JList arg0, Object arg1,
			int arg2, boolean arg3, boolean arg4) {
		JLabel c = (JLabel) super.getListCellRendererComponent(arg0, arg1,
				arg2, arg3, arg4);
		if (arg1 != null) {
			if (arg1.getClass().equals(User.class)) {
				User e = (User) arg1;
				c.setText(capitalizeFirstLetter(e.getFirstName()) + " " + capitalizeFirstLetter(e.getLastName()));
			} else
				c.setText(arg1.toString());
		}
		return c;
	}				
	public static String capitalizeFirstLetter(String value) {
		if (value == null) {
			return null;
		}
		if (value.length() == 0) {
			return value;
		}
		StringBuilder result = new StringBuilder(value.toLowerCase());
		result.replace(0, 1, result.substring(0, 1).toUpperCase());
		return result.toString();
	}
}
